home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / ch < prev    next >
Text File  |  1987-10-10  |  2KB  |  55 lines

  1. #    This shell program 'ch' could be in /usr/bin
  2. #    and it is written to use the directory /usr/scratch.
  3. #
  4. #
  5. #    /usr/bin/ch
  6. #    ===========
  7. #
  8. us=/usr/scratch
  9. >  $us/..temp
  10. for i in $*
  11. do
  12.     echo "$i" >>  $us/..temp
  13. done
  14. tail +3 $us/..temp  >$us/.temp
  15. sed "s/$1/$2/" $us/.temp  >$us/..temp
  16. <$us/.temp  tr \\12 \\40  >$us/temp.
  17. <$us/..temp  tr \\12 \\40  >$us/temp..
  18. echo 'mv ' >$us/.temp
  19. echo >>$us/.temp
  20. echo >>$us/temp.
  21. echo >>$us/temp..
  22. cat $us/temp. $us/temp.. $us/.temp > $us/..temp
  23. tp $us/..temp > $us/.temp
  24. awk '{print $3, $1, $2}' $us/.temp >$us/temp.
  25. sh < $us/temp.
  26. rm $us/.temp $us/..temp $us/temp. $us/temp..
  27. #
  28. #    This shell program changes filenames taking advantage of
  29. #    existing filename matching capabilities of the shell.
  30. #    The shell supplies a list of filenames to be edited after
  31. #    the first three arguments on the command line.
  32. #
  33. #    The first, arg(0), is the command `ch'.
  34. #    The second, arg(1), is the search pattern in the filename - a la `ed'
  35. #    The third, arg(2), is the substitute string.
  36. #
  37. #    As an example, to prefix all filenames in the current directory
  38. #    that ends in `.c' with the underscore; we issue the command:
  39. #
  40. #        ch  '^' _  *.c
  41. #
  42. #    Our current directory with the following files:
  43. #
  44. #        proga.c        progb.c        progc.c        progd.c
  45. #        xanother    yanother    zanother
  46. #
  47. #    would look like this after the execution of the shell program `ch':
  48. #
  49. #        _proga.c    _progb.c    _progc.c    _progd.c
  50. #        xanother    yanother    zanother
  51. #
  52. #    Note that the ch file should be placed in /usr/bin with mode 775.
  53. #    Also, this program needs a shared scratch directory `/usr/scratch'
  54. #    with mode 777.  Both should be owned by `root'.
  55.  ä.